package mygang.model;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 23/02/2013
 */
public class TableModel implements OptionInterface {

    protected String name;
    protected List<ColumnModel> columns;

    public TableModel(String name){
        this.name = name;
        this.columns = new ArrayList<ColumnModel>();
    }
    
    public TableModel(String name, List<ColumnModel> columns){
        this(name);
        this.columns = columns;
    }

    public void setColumns(List<ColumnModel> columns) {
        this.columns = columns;
    }

    public List<ColumnModel> getColumns() {
        return columns;
    }

    public String getName() {
        return name;
    }
    
    public ColumnModel getPrimaryColumn(){
        if(columns==null) return null;
        for(ColumnModel column : columns){
            if(column.isPrimary()) return column;
        }
        return null;
    }

    public Option toOption() {
        return new Option(getName(), getName());
    }

    @Override
    public boolean equals(Object obj) {
        return getName().equals(((TableModel)obj).getName());
    }
}